package domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.FetchMode;
import org.hibernate.annotations.Fetch;
@Entity
@Table(name="t_user")
public class User {
	private String shopOrPerson;
	private String email;
	private int id;
	private String name;
	private String account;//�˺�
	private String password;
	private String telePhone;
	private String school;
	private String sex;
	private Date createDate;
	private UserImg ui;
	private Map<String,User> fan_user = new HashMap<String,User>();
	private List<User> fans = new ArrayList<User>();
	private List<User> faned = new ArrayList<User>();//喜欢他的人
//	private List<Item> 
	private List<Message> sendMess = new ArrayList<Message>();//发送的信息
	private List<Message> recMess = new ArrayList<Message>();//接受的信息
//	
	private List<Item> sellItem = new ArrayList<Item>();
	private List<Item> buyFaned = new ArrayList<Item>();
	
	
	
	public String getShopOrPerson() {
		return shopOrPerson;
	}

	public void setShopOrPerson(String shopOrPerson) {
		this.shopOrPerson = shopOrPerson;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@OneToMany
	@JoinColumn(name="sell_user_id")
	public List<Item> getSellItem() {
		return sellItem;
	}
	
	public void setSellItem(List<Item> sellItem) {
		this.sellItem = sellItem;
	}
	@OneToMany
	@JoinColumn(name="wantbuy_user_id")
	public List<Item> getBuyFaned() {
		return buyFaned;
	}
	public void setBuyFaned(List<Item> buyFaned) {
		this.buyFaned = buyFaned;
	}
	@OneToMany
	@JoinColumn(name="faned_id")
	public List<User> getFans() {
		return fans;
	}
	public void setFans(List<User> fans) {
		this.fans = fans;
	}
	@OneToMany
	@JoinColumn(name="fan_id")
	public List<User> getFaned() {
		return faned;
	}
	public void setFaned(List<User> faned) {
		this.faned = faned;

	}
	
	
//	
	@OneToMany
	@JoinColumn(name="send_user")
	public List<Message> getSendMess() {
		return sendMess;
	}
	public void setSendMess(List<Message> sendMess) {
		this.sendMess = sendMess;
	}
	@OneToMany
	@JoinColumn(name="rec_user")
	public List<Message> getRecMess() {
		return recMess;
	}
	public void setRecMess(List<Message> recMess) {
		this.recMess = recMess;
	}
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="user_img_id")
	public UserImg getUi() {
		return ui;
	}
	
	
	@ManyToMany
	@MapKey(name="id")
	@JoinTable(name="fan_user", joinColumns={@JoinColumn(name="fan_id")}, inverseJoinColumns={@JoinColumn(name="faned_id")})
	public Map<String, User> getFan_user() {
		return fan_user;
	}
	public void setFan_user(Map<String, User> fan_user) {
		this.fan_user = fan_user;
	}
	public void setUi(UserImg ui) {
		this.ui = ui;
	}
	
	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@Override
	public String toString() {
		return "User [name=" + name + ", account=" + account + ", password="
				+ password + ", telePhone=" + telePhone + ", school=" + school
				+ ", sex=" + sex + ", createDate=" + createDate + "]";
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getTelePhone() {
		return telePhone;
	}
	public void setTelePhone(String telePhone) {
		this.telePhone = telePhone;
	}
	public String getSchool() {
		return school;
	}
	public void setSchool(String school) {
		this.school = school;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	
}
